package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 查看班级编号为1的学生的id,name,job,age
 */
public class Test {
    public static void main(String[] args) {

        try (Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            String sql = "SELECT id,name,job,age " +
                    "FROM student " +
                    "WHERE class_id=1";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int id = rs.getInt("id");
                String name = rs.getString("name");
                String job = rs.getString("job");
                int age = rs.getInt("age");
                System.out.println(id + "," + name + "," + job + "," + age);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
